use crate::{Error, mock::*};
use frame_support::{assert_ok, assert_noop,debug::debug};
use super::*;

#[test]
fn create_claim_works() {
	new_test_ext().execute_with(||{
		let claim = vec![0,10];
		assert_ok!(PoeModule::create_claim(Origin::signed(1),claim.clone()));
		assert_eq!(
			Proofs::<Test>::get(&claim),
			(1,frame_system::Pallet::<Test>::block_number()
		));
	
	})
}


#[test]
fn create_claim_failed_when_claim_already_exist(){
	new_test_ext().execute_with(||{
		let claim = vec![0,10];
		let _ = PoeModule::create_claim(Origin::signed(1),claim.clone());
		assert_noop!(
			PoeModule::create_claim(Origin::signed(1),claim.clone()),
			Error::<Test>::ProofAlreadyExist
		);
	})
}

#[test]
fn revoke_claim_works() {
	new_test_ext().execute_with(||{
		let claim = vec![0,10];
		let _ = PoeModule::create_claim(Origin::signed(1),claim.clone());
		assert_ok!(PoeModule::revoke_claim(Origin::signed(1),claim.clone()));
		assert_eq!(Proofs::<Test>::get(&claim),(0,0));
	})
}

#[test]
fn remove_claim_failed_when_claim_not_exist(){
	new_test_ext().execute_with(||{
		let claim = vec![0,10];
		assert_noop!(
			PoeModule::revoke_claim(Origin::signed(1),claim.clone()),
			Error::<Test>::NotClaimOwner
		);
	})
}

#[test]
fn transfer_claim() {
	new_test_ext().execute_with(||{
		let claim = vec![0,10];
		PoeModule::create_claim(Origin::signed(1),claim.clone());
		let _ = PoeModule::transfer_claim(Origin::signed(1),claim.clone(),2);
		assert_eq!(
			Proofs::<Test>::get(&claim),
			(2,frame_system::Pallet::<Test>::block_number()
		));
	})
}


#[test]
fn transfer_claim_not() {
	new_test_ext().execute_with(||{
		let claim = vec![0,10];
		PoeModule::create_claim(Origin::signed(1),claim.clone());
		let _ = PoeModule::transfer_claim(Origin::signed(1),claim.clone(),2);
		assert_noop!(
			PoeModule::revoke_claim(Origin::signed(1),claim.clone()),
			Error::<Test>::NotClaimOwner
		);
	})
}


#[test]
fn create_claim_works_low_max_len() {
	new_test_ext().execute_with(||{
		let claim = vec![0,10];
		assert_ok!(PoeModule::create_claim(Origin::signed(1),claim.clone()));
	})
}

#[test]
fn create_claim_works_max_len() {
	new_test_ext().execute_with(||{
		let claim = vec![100,101,3];
		assert_noop!(
			PoeModule::create_claim(Origin::signed(1),claim.clone()),
			Error::<Test>::ErrorMaxLen
		);
	})
}  